package com.service;

import com.dao.EmployeeDao;
import com.dao.impl.EmployeeDaoImpl;
import entity.EmpEntity;

import java.util.List;

public class EmployeeServiceImpl {
    private EmployeeDao dao = new EmployeeDaoImpl();

    public List<EmpEntity> getAllByPageHelper(int pageNum, int pageSize) {
        // 下面的代码模拟项目中可能产生的异常
        // mybatis 只要出错，一定是 PersistenceException 的子类，它是一个 RuntimeException
        /*Random random = new Random();
        int result = random.nextInt(10);
        if (result > 5) {
            throw new RuntimeException("模拟抛出异常");
        }*/
        return dao.getAllByPageHelper(pageNum, pageSize);
    }

    // 自定义分页
    public List<EmpEntity> getAllByCustom(int pageNo, int pageSize) {
        int offset = (pageNo - 1) * pageSize;
        int limit = pageSize;
        return dao.getAllByCustom(offset, limit);
    }

    // 分页加数字
    public int getCountByCustom() {
        return dao.getCountByCustom();
    }
}
